package com.duqc.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * @ClassName RedisListenerConfig
 * @Description redis 监听key值过期-定义配置RedisListenerConfig
 * 为防止服务器挂掉期间不能监听到已经过期的key，需添加一个定时任务，轮询的查询已经过期的key
 * 注意redis.conf中的notify-keyspace-events属性
 * @Author duqc
 * @Date 2022/2/15
 **/
@Configuration
public class RedisListenerConfig {

    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        return container;
    }

}
